Ext.define('PJ.view.registrationmanagement.SignUpUintAddUserList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.suuAddUserList'],
    
    initComponent: function(){
        this.columns = [{
            header: '审核状态',
            dataIndex: 'c.auditing_State',
            width: 125,
            //sortable: false,
            renderer: function(v, meta, record){
            	meta.style="padding-bottom: 0px;padding-top: 0px;line-height: 19px;padding-left: 0px;";
                var text = "",tipText="";
                if (v == 3) {
                	tipText="报名待审核";
                	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">报名待审核</div>';
                }
                else if (v == 1) {
                	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过</div>';
                	tipText="报名通过";
                }else if (v == 2) {
                	tipText="点击查看驳回原因";
                	text= '<div style="border-left:5px solid red;height:19px;cursor: pointer;padding-left:2px;"><span style="cursor: pointer;color:blue;">报名未通过</span></div>';
                }else if(v == 4){
                	tipText="撤销待审核";
                	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">撤销待审核</div>';
                }else if(v == 5){
                	tipText="报名通过(撤销未通过)";
                	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过(<span style="cursor: pointer;color:blue;">撤销未通过</span>)</div>';
                }
                meta.tdAttr = 'data-qtip="' + tipText + '" auditStatus=' + record.get("t.auditingState") + ' classUserId=' + record.get("classUserId") + ' userId=' + record.get("userId");
                return text;
            },
    		listeners: {
    			click: function(g, clm){
//    				var userId = clm.getAttribute("userId");
    				var auditStatus = clm.getAttribute("auditStatus");
    				var classUserId = clm.getAttribute("classUserId");
    				if(auditStatus == 5){
    					var win = Ext.create('PJ.view.registrationmanagement.CheckEdit', {
        					title: "查看驳回原因",
        					flag:4,
        					grid: me,
        					isDisable:false,
        					isReadOnly:true
        				}).show();
        				var actionName = "load";
        				if(gj_onlineLearning_constant.loadType == "jsonp"){
        					actionName = "loadJsonp";
        				}
        				win.down("form").getForm().doAction(actionName,{
        					url:me.store.findRejectReasonUrl,
        					params:{
        						classUserId: classUserId
        					},
        					success:function(f,action){
        					}
        				});
    				}else if(auditStatus == 2){
    					var win = Ext.create('PJ.view.trainingmanagement.CheckEdit', {
        					title: "查看驳回原因",
        					flag:4,
        					grid: me,
        					isDisable:false,
        					isReadOnly:true
        				}).show();
        				var actionName = "load";
        				if(gj_onlineLearning_constant.loadType == "jsonp"){
        					actionName = "loadJsonp";
        				}
        				win.down("form").getForm().doAction(actionName,{
        					url:me.store.findCommentUrl,
        					params:{
        						classUserId: classUserId
        					},
        					success:function(f,action){
        					}
        				});
    				}else{
    					return;
    				}
    			}
    		}
        },{
        	header: '学员帐号',
        	dataIndex: 'bu.login_ID',
        	width: 110
        },{
        	header: '姓名',
        	dataIndex: 'c.user_Name',
        	width: 110,
        	editor: {
        		xtype: 'textfield',
        		maxLength: 10,
        		listeners: {
        			blur: function(item){
        				var grid = item.up("grid");
        				var record = grid.getSelectionModel().getLastSelected();
        				var bforeLimit = record.get("i.userName");
        				var searchId = record.get("userId");
        				var value = item.getValue(); // 得到修改后的值
        				if(value.length > 10){
                			Orchid.alert('提示','该输入项最多输入10个字符！');
                			return;
                		}
        				if(value == null || value ==""){
        					Ext.Msg.alert('提示', "请重新输入要更改的人员姓名");
        				}else if(value==bforeLimit){
        					return;
        				}else{
        					if(gj_onlineLearning_constant.loadType == "jsonp"){
        						var store = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
        							url: grid.store.updateUrl,
        							extraParams: {
        								userid:searchId,
        								userName:value,
        								"springmvc.TOKEN": item.token
        							},
        							loadType:gj_onlineLearning_constant.loadType
        						});
        						store.load(function(rec, operation, success){
        							if (success) {
        								Ext.Msg.alert('消息', operation.response.msg, function(){
        									grid.store.load();
        								});
        							}else {
        								Ext.Msg.alert('消息', operation.error);
        							}
        						});
        					}else if(gj_onlineLearning_constant.loadType == "ajax"){
        						Ext.Ajax.request({
        							url: grid.store.updateUrl,
        							params: {
        								userid:searchId,
        								userName:value,
        								"springmvc.TOKEN": item.token
        							},
        							success: function(response){
        								var data = response.responseText;
        								var json = Ext.decode(data, true);
        								if (json.success) {
        									Ext.Msg.alert('消息', json.msg, function(){
            									grid.store.load();
        									});
        								}
        								else {
        									Ext.Msg.alert('消息', json.msg);
        								}
        							}
        						});
        					}else{
        						return
        					}
        				}
        			}
        		}
        	}
        }, {
            header: '性别',
            dataIndex: 'c.sex_code',
            width: 50
        },{
            header: '年龄',
            dataIndex: 'c.birthday',
            flex:1,
            minWidth: 50,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '民族',
            dataIndex: 'c.folk_Code',
            flex:1,
            minWidth: 80,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },{
            header: '手机号',
            dataIndex: 'c.mobile_Telephone',
            width: 100
        }, {
            header: '单位及职务',
            dataIndex: 'c.duty_Remark',
            flex:1,
            minWidth: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },/* {
            header: '联系电话',
            dataIndex: 'c.mobile_Telephone',
            flex:1,
            minWidth: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },*/ {
            header: '备注',
            dataIndex: 'c.remark',
            flex:1,
            minWidth: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }];
        this.store = Ext.create('PJ.' + prototype + '.registrationmanagement.SignUpUintAddUserList', {
            isLoad: false
        });
        //实现排序序号的编辑
        this.plugins = [Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit: 1,
            listeners: {
                beforeedit: function(editor, e){
                    var textfield = e.column.getEditor();
                    if(gj_onlineLearning_constant.loadType == "jsonp"){
                    	var storeToken = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
                    		loadType: gj_onlineLearning_constant.loadType,
                    		url: gj_onlineLearning_constant.tokenUrl
                    	});
                    	storeToken.load(function(rec, operation, success){
                    		var token = operation.response;
                    		textfield.token = token;
                    	});
                    }else if(gj_onlineLearning_constant.loadType == "ajax"){
                    	Ext.Ajax.request({
                            url: tokenUrl,
                            success: function(response){
                                var data = response.responseText;
                                var token = Ext.decode(data, true);
                                textfield.token = token;
                            }
                        });
                    }
                }
            }
        })];
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },
    
    //更新
    onUpdateClick: function(button){
        var me = this;
        var records = me.getSelectionModel().getSelection();
        win = Ext.create('PJ.view.registrationmanagement.UpdateUser',{
        	title: "更新人员信息",
        	grid: me
        }).show();
        if(gj_onlineLearning_constant.loadType == "jsonp"){
        	var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
        		loadType: gj_onlineLearning_constant.loadType,
        		url: me.store.preUpdateUrl,
        		extraParams: {
        			openState:me.up('window').openState,
        			searchClassUserIds: records[0].get("classUserId")//登录ID
        		}
        	});
        	store1.load(function(rec, operation, success){
        		var msg = success == true ? '操作成功！' : operation.error;
    			Orchid.alert('消息', msg, function(){
					var store = me.getStore();
					store.load();
				});
        	});
        }else if(gj_onlineLearning_constant.loadType == "ajax"){
        	Ext.Ajax.request({
        		url: me.store.preUpdateUrl,
        		params: {
        			openState:me.up('window').openState,
        			searchClassUserIds: records[0].get("classUserId")//登录ID
        		},
        		success: function(response){
        			var data = response.responseText;
        			var json = Ext.decode(data, true);
        			win.down('form').getForm().findField("userid").setValue(json.result.userId);
        			win.down('form').getForm().findField("userName").setValue(json.result.userName);
        			win.down('form').getForm().findField("loginId").setValue(json.result.loginId);
        			win.down('form').getForm().findField("deptName").setValue(json.result.deptName);
        		}
        	});
        }
    },
    //撤销报名
    onUnSignUpClick: function(button){
        var me = this;
        var records = this.getSelectionModel().getSelection();
        Ext.Msg.confirm({
            title: '提示',
            msg: '您确定要为这些学员撤销报名吗？',
            buttons: Ext.Msg.OKCANCEL,
            fn: function(id){
                if (id == 'ok') {
                    var userIds = new Array();
                    Ext.Array.each(records, function(name, index){
                    	userIds.push(name.get("classUserId"));
                    });
                    if(gj_onlineLearning_constant.loadType == "jsonp"){
                    	var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
                    		loadType: gj_onlineLearning_constant.loadType,
                    		url: me.store.unSignUpUrl,
                    		extraParams: {
                    			openState: me.up('window').openState,
                    			searchClassUserIds: userIds
                    		}
                    	});
                    	store1.load(function(rec, operation, success){
                    		var msg = success == true ? '操作成功！' : operation.error;
                			Orchid.alert('消息', msg, function(){
            					var store = me.getStore();
            					store.load();
            					me.up('window').down("psuuAddUserList").getStore().load();//刷新待选列表
            				});
                    	});
                    }else if(gj_onlineLearning_constant.loadType == "ajax"){
                    	Ext.Ajax.request({
                    		url: me.getStore().unSignUpUrl,
                    		params: {
                    			openState: me.up('window').openState,
                    			searchClassUserIds: userIds
                    		},
                    		success: function(response){
                    			var data = response.responseText;
                    			var json = Ext.decode(data, true);
                        		var msg = json.success == true ? '操作成功！' : json.msg;
                    			Orchid.alert('消息', msg, function(){
                					var store = me.getStore();
                					store.load();
                					me.up('window').down("psuuAddUserList").getStore().load();//刷新待选列表
                				});
                    		}
                    	});
                    }
                }
                else {
                    return;
                }
            }
        });
    },

    listeners: {
        //点击列表数据时显示按钮事件
    	selectionchange: function(selModel, selected){
    		this.down('#' + this.oldId + "UnSignUp").setDisabled(selected.length === 0);//撤销报名
    	},
        viewready: function(){
            this.addDocked([{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [/*this.updateButton, "-", */{
                    text: '撤销报名',
                    iconCls: 'publishCancelIco',
                    itemId: this.oldId + "UnSignUp",
                    disabled: true,
                    scope: this,
                    handler: this.onUnSignUpClick
                }, "->", "->", this.countSelectPanel]
            }]);
            var me = this;
            // 触发权限过滤事件
            me.fireEvent("permission", this);
            var params = me.store.proxy.extraParams;
            var newParams = {
            		searchDepId: me.up('window').deptId,
            		searchClassID: me.up('window').classId
            };
            Ext.apply(params, newParams);
            this.store.isLoad = true;
            this.store.load();
        }
    }
});
